import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import * as path from "path"
import electron from "vite-plugin-electron"
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Inspect from 'vite-plugin-inspect'
// import polyfillExports from "vite-plugin-electron-renderer"
// import electronRenderer from "vite-plugin-electron/renderer";
// import polyfillExports from "vite-plugin-electron/polyfill-exports";

const pathSrc = path.resolve(__dirname, 'src')
// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '@': pathSrc,
    },
  },
  css: {
    preprocessorOptions: {
      // scss:{

      // }
    },
  },
  // base:"./",
  plugins: [

    vue(),
    electron([{
      entry: "electron-main/index.ts", // 主进程文件
      // onstart: options => {
      //   // 多个页面时，自定义启动页面
      //   options.startup(['.', '--no-sandbox'])
      // },
    },
    // {
      // entry: 'electron-preload/index.js',
      // onstart(options) {
      //   // 重载preload文件为ts文件
      //   options.reload()
      // },
    // }
  ]),


    // ...
    AutoImport({
      // Auto import functions from Vue, e.g. ref, reactive, toRef...
      // 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
      // imports: ['vue'],
      resolvers: [
        ElementPlusResolver(),
        // Auto import icon components
        // 自动导入图标组件
        IconsResolver({
          prefix: 'Icon',
        }),
      ],
      dts: path.resolve(pathSrc, 'auto-imports.d.ts'),
    }),
    Components({
      resolvers: [
        // Auto register icon components
        // 自动注册图标组件
        IconsResolver({
          enabledCollections: ['ep'],
        }),
        ElementPlusResolver()
      ],
      dts: path.resolve(pathSrc, 'components.d.ts'),
    }),
    Icons({
      compiler: 'vue3',
      autoInstall: true,
    }),

    Inspect(),
  ],
  build: {
    emptyOutDir: false, // 默认情况下，若 outDir 在 root 目录下，则 Vite 会在构建时清空该目录
  },
})
